package com.qst.service;

import com.qst.dao.DepartmentDao;
import com.qst.dao.IEmployeeDao;
import com.qst.pojo.Department;
import com.qst.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author KungSu.
 * @create 2021-06-17 10:51
 */
@Service
public class DepartmentService {
    @Autowired
    DepartmentDao departmentDao;

    @Autowired
    IEmployeeDao employeeDao;

    public List<Department> selectDep() {
        return departmentDao.findDep();
    }
    public List<Employee> selectEmployeeByDp(int dpId) {
        return employeeDao.findEmployeeByDepartmentId(dpId);
    }
    public boolean delDep(Integer id) {

        List<Employee> employees = employeeDao.findEmployeeByDepartmentId(id);

        if(employees != null && employees.size() != 0) {
            return false;
        }

        departmentDao.delDep(id);
        return true;
    }

    public void insertDep(String name) {
        departmentDao.insertDep(name);
    }


}
